
using System;
using System.Collections.Generic;
using System.Threading;
using System.Windows.Forms;

using Derm.Render;

namespace Derm.Examples
{
	static class Program
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main()
		{
			
			//Application.EnableVisualStyles();
			//Application.SetCompatibleTextRenderingDefault(false);

			// Define window
			RenderWindow rWindow = new RenderWindow(1024, 768);

			rWindow.DefineColorBuffer(Pixel.Type.RGB24, RenderSurface.BufferPolicy.RequiredAndDegradable);
			rWindow.DefineDepthBuffer(24, RenderSurface.BufferPolicy.RequiredAndDegradable);
			rWindow.DefineDoubleBuffers(true, RenderSurface.BufferPolicy.RequiredAndDegradable);
			rWindow.ShowWindow();

			// Define render pipeline
			ExamplePipeline rPipeline = new ExamplePipeline(rWindow);
			// Create kernel
			sMainRenderKernel = new RenderKernel();
			sMainRenderKernel.RegisterPipeline(rPipeline);
			RenderKernel.RegisterKernel(sMainRenderKernel);

			DateTime start;
			TimeSpan offset;
			Matrix4x4 m1 = new Matrix4x4(), m2 = new Matrix4x4();

			start = DateTime.Now;
			for (uint i = 0; i < 1000000; i++) {
				m1 = m1 * m2;
			}
			offset = DateTime.Now - start;

			MessageBox.Show(offset.TotalMilliseconds.ToString());

			Derm.Simd.SimdLibrary.LoadSimdExtensions();

			start = DateTime.Now;
			for (uint i = 0; i < 1000000; i++) {
				m1 = m1 * m2;
			}
			offset = DateTime.Now - start;

			MessageBox.Show(offset.TotalMilliseconds.ToString());

			// Run for 10 seconds the "ColoredUnitCube"
			rPipeline.SetExample("ColoredUnitCube");
			RenderKernel.RunKernels();
			Thread.Sleep(10000);

			// Run for 10 seconds the example pipeline
			rPipeline.SetExample("ColoredUnitCube");
			RenderKernel.RunKernels();
			Thread.Sleep(10000);

			RenderKernel.StopKernels();
		}

		/// <summary>
		/// Application render kernel.
		/// </summary>
		private static RenderKernel sMainRenderKernel;
	}
}